<template>
    <view class="uplogo">
        <view class="bigUpImag" @tap="addImag">
                <view class="upimag" v-if="url">
                    <image :src="url" mode="aspectFill" />
                </view>
                <image src="/static/images/bigUpImag.png" class="bg" />
        </view>
        <button class="submit"  :disabled="!url" @tap="submitHandle">保存</button>
    </view>
</template>
<script>

import {postUpLoadFile,postUpHead} from '@/request/actions'


export default {
        
         
          data(){
              return{
                  url:"",
                  bStop:false,
                  salonId:''
              }
             
          },
            methods:{
                addImag(){

                    let count =1;
                      
                    uni.chooseImage({
                        count,
                        sizeType:'compressed',
                        success: res => {
                                
                                if(res.errMsg == "chooseImage:ok"){
                                    
                                    let path = res.tempFilePaths[0]

                                  
                                   
                          

                                            postUpLoadFile(path).then(r=>{
                                           
                                                    let {data:res} = r;
                                                    res = JSON.parse(res);
                                                    
                                                    if(res.status == 200){
                                                        this.url = res.data;
                                                       
                                                    }
                                                    
                                                    
                                                    
                                               
                                                  
                                                })

                               
                          



                          }
                              
                                   
                               
                        


                            }
                        })

             
                },
                  submitHandle(){
                    let salonPicture = this.url;
                    let globalData = getApp().globalData;
                    let salonId =  this.salonId;
                    if(this.bStop)return;
                    this.bStop = true;
                    postUpHead({salonPicture,salonId}).then(r=>{
                            let {data:res} = r;
                            this.bStop = false;
                            if(res.status == 200){
                                uni.showModal({
                                    content:'店铺logo设置成功',
                                    showCancel:false,
                                    success:res=>{
                                        uni.navigateBack();
                                    }
                                })
                            }

                    })
            }
        },
        onLoad(query){
            
            this.salonId = query.salonId
        }
}
</script>
<style lang="scss">
    .uplogo{
        min-height: 100vh;
        box-sizing: border-box;
        border-top: 20rpx solid #f5f5f5;
        padding: 20rpx;
        .submit{
            height: 80rpx;
            border-radius: 40rpx;
            background: $my-main-color;
            color:#fff;
            font-size: 35rpx;
            padding: 0;
            border: none;
            &:after{
                border: none;
            }
        }
        .bigUpImag{
            width: 310rpx;
            height: 310rpx;
            margin: 140rpx auto;
            position: relative;
            .bg{
                width: 100%;
                height: 100%;
                position: relative;
                z-index: 1;
            }
        }

        .upimag{
            width: 310rpx;
            height: 310rpx;
            position: absolute;
            top:0rpx;
            left:0%;
            z-index: 2;
            image{
                border-radius: 155rpx;
                width: 100%;
                height: 100%;
            }
        }
    }
</style>

